<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>div1</div>
    <div>div2</div>
    <div>div3</div>
    <script>
        // 函数 调用时执行的  可重复使用的代码块
        // let i = 10;
        // let fn1 = function () {
        //     console.log(i);
        // }
        // i = 20
        // i = 30
        // fn1
        
        var arr = []
        for (var i = 0; i <= 5; i++) {
            arr[i] = function () {
                console.log(i);
            }            
        }
        console.log(arr);
        console.log(i);
        arr[0]()
        
        var divArr = document.querySelectorAll("div")
        {
            var i = 0
            divArr[i].onclick = function () {
                console.log(divArr);
                console.log(i);
                divArr[i].style.color = "red"
            }
        }
    </script>
</body>
</html>